package com.th.supcom.pds.dispensedrug.client.widget;

import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;

/**
 * 核对发药主面板.
 * 
 * @author 杨冲
 */
public class DispenseDrugMainPanel extends ContentPanel
{
    /** 提交路径. */
    public static final String SCC_BRANCH = "$URL$";
    /** 提交日期. */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";
    /** 最终修改人员. */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";
    /** 最终版本号. */
    public static final String SCC_REVISION = "$Revision$";
    private DispenseDrugButtons m_buttons;
    private DispenseDrugAction m_dispenseAction;

    private DispenseDrugRecipeDetailPanel m_dispenseDrugRecipeDetailPanel;

    private DispenseDrugFields m_fields;

    private DispenseDrugRecipePanel m_recipePanel;

    public DispenseDrugMainPanel ()
    {
        initUI ();
        initAction ();
        initListeners ();
        initData ();
    }

    /**
     * 初始化事件
     */
    private void initAction ()
    {
        m_dispenseAction = new DispenseDrugAction ();
        m_dispenseAction.setDispenseDrugFields (m_fields);
        m_dispenseAction.setDispenseDrugRecipeDetailPanel (m_dispenseDrugRecipeDetailPanel);
        m_dispenseAction.setDispenseDrugRecipePanel (m_recipePanel);
    }

    /**
     * 初始化数据
     */
    private void initData ()
    {
        m_dispenseAction.findRecipeByCondition (m_fields.getConsumeProofField (), m_fields.getConsumeProofField ());
    }

    /**
     * 初始化事件监听
     */
    private void initListeners ()
    {
        DispenseDrugListener dispenDrugListener;
        dispenDrugListener = new DispenseDrugListener ();
        dispenDrugListener.setDispenseDrugAction (m_dispenseAction);
        dispenDrugListener.setDispenseDrugButtons (m_buttons);
        dispenDrugListener.setDispenseDrugFields (m_fields);
        dispenDrugListener.setRecipePanel (m_recipePanel);
        dispenDrugListener.setKeyNavComponent (this);
        dispenDrugListener.initListeners ();
    }

    /**
     * 初始化UI
     */
    private void initUI ()
    {
        this.setHeaderVisible (false);
        this.setLayout (new BorderLayout ());

        m_buttons = new DispenseDrugButtons ();
        m_fields = new DispenseDrugFields ();
        m_dispenseDrugRecipeDetailPanel = new DispenseDrugRecipeDetailPanel ();
        final DispenseDrugDetailPanel dispenseDrugDetailPanel = new DispenseDrugDetailPanel (m_dispenseDrugRecipeDetailPanel);
        final DispenseDrugPatientInfoPanel recipeFeePatientInfoPanel = new DispenseDrugPatientInfoPanel (m_fields, m_buttons);
        m_recipePanel = new DispenseDrugRecipePanel ();

        final BorderLayoutData centerData = new BorderLayoutData (LayoutRegion.CENTER, 700);
        centerData.setMargins (new Margins (0, 0, 0, 0));
        final BorderLayoutData westData = new BorderLayoutData (LayoutRegion.WEST, 250);
        westData.setMargins (new Margins (2, 0, 2, 5));
        final BorderLayoutData northData = new BorderLayoutData (LayoutRegion.NORTH, 150);
        northData.setMargins (new Margins (0, 5, 0, 5));

        add (recipeFeePatientInfoPanel, northData);
        add (dispenseDrugDetailPanel, centerData);
        add (m_recipePanel, westData);
        setBottomComponent (createColorShow ());
    }

    private ToolBar createColorShow ()
    {
        ToolBar toolBar;
        toolBar = new ToolBar ();
        String txt = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
                     + "<span class='redTendGrade'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;为本窗口待发药</spqn>";
        Label lab = new Label (txt);
        lab.setStyleAttribute ("margin-left", "10px");
        toolBar.add (lab);
        return toolBar;
    }
}